import { createRouter, createWebHashHistory } from 'vue-router';

const routes = [
  {
    name: 'notFound',
    path: '/:path(.*)+',
    redirect: {
      name: 'home',
    },
  },
  {
    name: 'home',
    path: '/home',
    component: () => import('./view/home'),
    meta: {
      title: '框架首页',
    },
  },
  {
    name: 'dome',
    path: '/dome',
    component: () => import('./view/dome'),
    meta: {
      title: '临时',
    },
  },
  {
    name: 'shop-home',
    path: '/shop-home',
    component: () => import('./view/shop-home'),
    meta: {
      title: '首页',
    },
  },
  {
    name: 'shop-class',
    path: '/shop-class',
    component: () => import('./view/shop-class'),
    meta: {
      title: '分类',
    },
  },
  {
    name: 'shop-buys',
    path: '/shop-buys',
    component: () => import('./view/shop-buys'),
    meta: {
      title: '购物车',
    },
  },
  {
    name: 'shop-ours',
    path: '/shop-ours',
    component: () => import('./view/shop-ours'),
    meta: {
      title: '我的',
    },
  },
  {
    name: 'shop-address',
    path: '/shop-address',
    component: () => import('./view/shop-address'),
    meta: {
      title: '收货地址',
    },
  },
  // 移动
  {
    name: 'mb-home',
    path: '/mb-home',
    component: () => import('./view/mb-home'),
    meta: {
      title: '首页',
    },
  },
  {
    name: 'mb-class',
    path: '/mb-class',
    component: () => import('./view/mb-class'),
    meta: {
      title: '分类',
    },
  },
  {
    name: 'mb-equity',
    path: '/mb-equity',
    component: () => import('./view/mb-equity'),
    meta: {
      title: '权益',
    },
  },
  {
    name: 'mb-ours',
    path: '/mb-ours',
    component: () => import('./view/mb-ouers'),
    meta: {
      title: '我的',
    },
  },
  {
    name: 'mb-vfp-setmeal',
    path: '/mb-vfp-setmeal',
    component: () => import('./view/mb-vfp-setmeal'),
    meta: {
      title: '我的套餐',
    },
  },
  
];

const router = createRouter({
  routes,
  history: createWebHashHistory(),
});

router.beforeEach((to, from, next) => {
  const title = to.meta && to.meta.title;
  if (title) {
    document.title = title;
  }
  next();
});

export { router };
